package com.heima.xxljob.job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TestJob {
    @Value("${xxl.job.executor.port}")
    private int port;
    @XxlJob("job-demo")
    public void job()
    {
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        for(int i=0;i<100;i++)
        {
            if (i%shardTotal==shardIndex)
                log.info("job-demo 执行了。。。端口：{},任务编号：{}",port,i);
        }
    }
}
